import yaml
from baseTools.tool_logger import *

class MyYaml:

    def __init__(self, file):
        try:
            logger.info('打开yaml文件')
            with open(file, 'r', encoding='utf-8') as f:
                self.re_yaml = yaml.safe_load(f)
                return
        except Exception as e:
            logger.error('打开yaml文件失败，报错信息为：{}'.format(e))

    def token_yaml(self):
        try:
            list1 = []
            logger.info('获取token数据')
            for i in self.re_yaml:
                list1.append((i.get('method'), i.get('url'), i.get('parameter')))
            return list1
        except Exception as e:
            logger.error('获取token文件数据失败，报错信息为：{}'.format(e))

    def department_create_yaml(self):
        try:
            list2 = []
            logger.info('获取创建部门数据')
            for i in self.re_yaml:
                list2.append((i.get('test_titlt'), i.get('test_level'), i.get('test_description'),i.get('method'),i.get('url'),i.get('body_data'),i.get('excepted')))
            return list2
        except Exception as e:
            logger.error('获取创建部门yaml文件数据失败，报错信息为：{}'.format(e))



if __name__ == '__main__':
    read_yaml = MyYaml('../baseDate/db_test_department_create.yaml')
    print(read_yaml.department_create_yaml())
